<#include "/template/common/layout.html"/> 
<@layout title="修改密码">

    <header class="order-filter">
        <a class="order-filter-cur" href="javascript:void(0)" id="waitPay" data-state="0">待处理</a>
        <a href="javascript:void(0)" id="waitPick" data-state="1">处理中</a>
        <a href="javascript:void(0)" id="finlyed" data-state="2">已经完成</a>
    </header>
    <form>
        <div class="orders-search">
            <input name="keyword" placeholder="请输入订单编号或商品名称" value="" id="keyword" type="text">
            <input value="搜索" id="search" type="submit">
        </div>
    </form>

    <section class="orders-list">
	</section>
    
    <section style="display: none;" id="loading">
        <img src="/images/loading.gif">
    </section>
    
<!-- <script src="/js/jquery.blackbox.js" type="text/javascript"></script> -->
<script>
	(function() {
		var state = parseInt('0'), pageindex = 1, pagesize = 20, isLoading = false, keyword = $("#keyword").val();
		//alert(state);
		$("#empty").hide();
		/* var PayEvent = function() {
			$(".orders-pay").on("click", function(e) {
				e.preventDefault();
				var orderid = $(this).data("orderid");
				Pay(orderid);
			})
		} */
		function LoadData() {
			$("#loading").show()
			isLoading = true;
			$.get("/front/getBookList?"
					+ "seach_status=" + state				
					+ "&pageindex=" + pageindex
					+ "&pagesize=" + pagesize,
			function(data) {
				//alert(data);
				if (data.totalPage >0) {
					var frontList =  data.list;
					for ( var i in frontList) {
						var order = frontList[i];
						var dom = '<dl id="order_' + order.id + '"><dt>预定用户：<a href="#">'
								+ order.customer_name+'['+ (order.customer_sex==1?"女士":"男士")+']'
								+ '</a><br> 预定时间：'
								+ (order.front_time==null?"":order.front_time)
								+ '</dt>';
								
							var dl = '<dd>'
									+ '<div class="orders-details">'
									+ '    <p><a href="#">电话'
									+ order.customer_phone
									+ '</a></p>'
									+ '    <p><span class="orders-money"><b>'
									+ '</b>就餐人数'
									+ (order.people_num==null?"0":order.people_num)
									+ '</span></p>'
									+ '</div></dd>';
							dom += dl;


						/*if (order.status == '5') {
							dom += '<a href="javascript:void(0);" data-orderid="'
									+ order.OrderId
									+ '">查看物流</a>';
						}*/

						dom += '</p></div></dd></dl>'
						$(".orders-list").append(dom);

					}
					pageindex++;
					$("#loading").hide();
					isLoading = false;
				} 
				/* else if (data.Code === 102) {
					isLoading = true;
					$("#loading").hide();
					if (pageindex == 0) {
						var empty = '<dl><dt>没有订单</dt></dl>';
						$(".orders-list").append(empty);
					}
				}  */
				else {
					//isLoading = false;
					isLoading = true;
					$("#loading").hide();
					if (pageindex == 0) {
						var empty = '<dl><dt>没有订单</dt></dl>';
						$(".orders-list").append(empty);
					}
				}
			})

		}
		function onScroll(event) {
			// Only check when we're not still waiting for data.
			if (!isLoading) {
				// Check if we're within 100 pixels of the bottom edge of the broser window.
				var closeToBottom = ($(window).scrollTop()
						+ $(window).height() > $(document).height() - 100);
				if (closeToBottom) {
					LoadData();
				}
			}
		};
		LoadData();
		$(window).scroll(onScroll);
		$("#search").click(function(e) {
			e.preventDefault();
			keyword = $("#keyword").val();
			$(".orders-list").empty();
			pageindex = 0;
			LoadData();
		})

		$("#waitPick,#waitPay,#finlyed").click(function(e) {
			e.preventDefault();
			state = $(this).data("state");
			//alert(state);
			keyword = "";
			$(".order-filter a").removeClass("order-filter-cur");
			$(this).addClass("order-filter-cur");
			$(".orders-list").empty();
			pageindex = 1;
			LoadData();
		});

		$(".orders-pay").on("click", function(e) {
			e.preventDefault();
			var orderid = $(this).data("orderid");
			console.log(orderid);

		})

		$(document).ready(function() {
			$(".order-filter a").each(function() {
				if ($(this).data("state") === state) {
					$(this).addClass("order-filter-cur");
				}
			})

		});

		function Pay(orderId) {
			$.get(baseuri + "Service/order.asmx/Pay?orderId=" + orderId,
			function(result) {
				if (result.Msg === 'Ok') {
					var data = result.Obj.api, pk = data["package"];
					pk["timestamp"] = getTimeStamp();
					var pck = getPackage(pk["body"],
							pk["notify_url"],
							pk["out_trade_no"],
							pk["partner"],
							pk["total_fee"],
							data["partnerkey"]);
					var paySign = getSign(
							data["appid"],
							data["appkey"],
							data["noncestr"],
							pk["timestamp"], pck);
					var params = {
						"appId" : data["appid"],
						"timeStamp" : pk["timestamp"],
						"nonceStr" : data["noncestr"],
						"package" : pck,
						"signType" : "SHA1",
						"paySign" : paySign
					};

					//alert(pck);
					//alert(paySign); 
					//alert(params.appId);
					WeixinJSBridge
							.invoke(
									'getBrandWCPayRequest',
									params,
									function(res) {
										if (res.err_msg == "get_brand_wcpay_request:ok") {
											Message("付款成功.正在跳转...");
											setTimeout(
													function() {
														window.location.href = baseuri
																+ "WXsdk/orders.aspx?type=30";
														;
													},
													200)

										} else {
											Message("付款未成功.正在跳转订单页...")
											setTimeout(
													function() {
														window.location.href = baseuri
																+ "WXsdk/orders.aspx?type=10";
														;
													},
													200)
										}
									});
				}
			})
		}

	})();
function ChangeOrder(orderId,status) {
	//alert(orderId+"--"+status);
	if(confirm("你确定要删除这件商品么?")){
		$.get("/orders/changeStatus?order.id=" + orderId + "&order.status=" + status, function(result) {
			if (result.Msg === 'Ok') {
				Message("订单已取消");
				$("#order_" + orderId).remove();
			}
		})
	}
    /* var box = new BlackBox();
	box.confirm("添加购物车成功,", 
	function(data) {
		
		if (data) {
			$.get("/orders/changeStatus?order.id=" + orderId + "&order.status=" + status, function(result) {
				if (result.Msg === 'Ok') {
					Message("订单已取消");
					$("#order_" + orderId).remove();
				}
			})
			return false;
		} else {

		}
	}, {
		title : '你确定要删除这件商品么?',
		value : '确定',
		channel : '放弃'
	}) */
}

</script>


</@layout>